package com.bps.zzant.model;

import static javax.persistence.GenerationType.IDENTITY;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.annotations.Sort;
import org.springframework.format.annotation.DateTimeFormat;

@Entity
@Table(name = "zzant_order_payment")
public class Payment implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6330107539245233086L;
	

	private int paymentId;
	private OrderGarment order;	
	private String paymentMethod;	
	private BigDecimal paymentAmount;	
	private String paymentType;
	private Date paymentDate;
	

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "payment_id")
	public int getPaymentId() {
		return paymentId;
	}

	public void setPaymentId(int paymentId) {
		this.paymentId = paymentId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "orders_id", nullable = false)
	@JsonIgnore
	public OrderGarment getOrder() {
		return order;
	}

	public void setOrder(OrderGarment order) {
		this.order = order;
	}
	
	@Column(name = "payment_method")
	public String getPaymentMethod() {
		return paymentMethod;
	}

	public void setPaymentMethod(String paymentMethod) {
		this.paymentMethod = paymentMethod;
	}

	@Column(name = "payment_amount")
	public BigDecimal getPaymentAmount() {
		return paymentAmount;
	}

	public void setPaymentAmount(BigDecimal paymentAmount) {
		this.paymentAmount = paymentAmount;
	}
	
	@Column(name = "payment_type")
	public String getPaymentType() {
		return paymentType;
	}

	public void setPaymentType(String paymentType) {
		this.paymentType = paymentType;
	}

	@Column(name = "payment_date")
	@DateTimeFormat(pattern = "MM/dd/YYYY")
	public Date getPaymentDate() {
		return paymentDate;
	}

	public void setPaymentDate(Date paymentDate) {
		this.paymentDate = paymentDate;
	}

	public Payment(OrderForm orderForm) {
		this.paymentMethod = orderForm.getPaymentMethod();
		
		String paymentAmount = orderForm.getPaymentAmount().replace(",", "");
		paymentAmount = paymentAmount.replace("$", "");
		
		this.paymentAmount = new BigDecimal(paymentAmount);
		this.paymentType = "initDown";
		this.paymentDate = new Date();
	}

	public Payment() {
		super();
	}

	public Payment(String paymentMethod, BigDecimal paymentAmount,
			String paymentType) {
		this.paymentMethod = paymentMethod;
		this.paymentAmount = paymentAmount;
		this.paymentType = paymentType;
		this.paymentDate = new Date();
	}
	

}
